package com.mdz.nc.Controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mdz.nc.Entity.Sbwhb;
import com.mdz.nc.Entity.SysNc;
import com.mdz.nc.Mapper.SbwhbMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 孟德志
 * @since 2020-04-13
 */
@Controller
@RequestMapping("/nc/sbwhb")
public class SbwhbController {

    @Autowired
    private SbwhbMapper sbwhbMapper;

    @ResponseBody
    @RequestMapping(value = "/insertsbwh",method = RequestMethod.POST)
    public int insertsbwh(Sbwhb sbwhb){
        LocalDate today = LocalDate.now();
        sbwhb.setWhrq(today);
        return sbwhbMapper.insert(sbwhb);
    }

    @ResponseBody
    @RequestMapping(value = "/getsbwhbysbbh",method = RequestMethod.GET)
    public String getsbwhbysbbh(@RequestParam int pageNumber, @RequestParam int pageSize, HttpServletResponse response, @RequestParam String sbbh){
        response.setContentType("text/json");
        response.setCharacterEncoding("utf-8");
        PageHelper.startPage(pageNumber, pageSize);
        List<Sbwhb> sbwhbs=sbwhbMapper.selectList(new QueryWrapper<Sbwhb>().like("sbbh",sbbh));
        PageInfo page=new PageInfo(sbwhbs);
        List<SysNc> rows = page.getList();
        int total = (int) page.getTotal();
        JSONObject result = new JSONObject();
        result.put("rows",rows);
        result.put("total",total);
        return result.toJSONString();
    }

    @ResponseBody
    @RequestMapping(value = "/getsbwhbywhrq",method = RequestMethod.GET)
    public String getsbwhbywhrq(@RequestParam int pageNumber, @RequestParam int pageSize, HttpServletResponse response, @RequestParam String startTime,@RequestParam String endTime){
        response.setContentType("text/json");
        response.setCharacterEncoding("utf-8");
        PageHelper.startPage(pageNumber, pageSize);
        List<Sbwhb> sbwhbs=sbwhbMapper.getsbwhbywhrq(pageNumber,pageSize,startTime,endTime);
        PageInfo page=new PageInfo(sbwhbs);
        List<SysNc> rows = page.getList();
        int total = (int) page.getTotal();
        JSONObject result = new JSONObject();
        result.put("rows",rows);
        result.put("total",total);
        return result.toJSONString();
    }
}

